import { http } from "@/utils/http";

interface CategoryList {
  code: number;
  message: string;
  data?: any;
  failed_categories?: any; // 用于批量删除时，返回未删除的分类信息
}

/** 获取文章分类列表*/
export const getArticleCategoryList = (data?: object) => {
  return http.request<CategoryList>("post", "/api/article-category/list", {
    data
  });
};
/** 获取文章分类详情*/
export const getArticleCategoryDetail = (data?: { id: string }) => {
  return http.request<CategoryList>("post", "/api/article-category/detail", {
    data
  });
};
/** 添加文章分类*/
export const addArticleCategory = (data?: {
  name: string;
  parent_id: number | null;
  sort?: number;
  icon?: string;
  display?: boolean;
}) => {
  return http.request<CategoryList>("post", "/api/article-category/add", {
    data
  });
};
/** 修改文章分类*/
export const updateArticleCategory = (data?: object) => {
  return http.request<CategoryList>("post", "/api/article-category/update", {
    data
  });
};
/** 删除文章分类*/
export const delArticleCategory = (data?: object) => {
  return http.request<CategoryList>("post", "/api/article-category/delete", {
    data
  });
};
/** 获取文章分类树形结构*/
export const getArticleCategoryTree = (params?: object) => {
  return http.request<CategoryList>("get", "/api/article-category/tree", {
    params
  });
};
